package com.bqtv.sport.dialog

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.bqtv.sport.adapter.SelectAddressAdapter
import com.bqtv.sport.adapter.SelectBankAdapter
import com.bqtv.sport.commen.utils.KeyboardUtils
import com.bqtv.sport.commen.widget.VerificationCodeEditText
import com.bqtv.sport.databinding.DialogPayBinding
import com.bqtv.sport.databinding.DialogSelectAddressBinding
import com.bqtv.sport.databinding.DialogSelectBankBinding
import com.bqtv.sport.databinding.DialogSelectPicBinding
import com.bqtv.sport.databinding.DialogWithdrawnBinding
import com.bqtv.sport.ui.mine.SetPayPswActivity
import com.chad.library.adapter4.BaseQuickAdapter
import com.hjq.base.BaseDialog
import com.hjq.base.BottomSheetDialog
import com.hjq.toast.Toaster

class PayDialog {
    class Builder(context: Context) : BaseDialog.Builder<Builder>(context) {
        var binding: DialogPayBinding =
            DialogPayBinding.inflate(
                LayoutInflater.from(context),
                FrameLayout(context),
                false
            )
        var mHandler: Handler? = null

        init {
            setContentView(binding.root)
            setData()
        }

        fun setData(): Builder {
            binding.verEdit.setOnInputTextListener(object :
                VerificationCodeEditText.OnInputTextListener {
                override fun onInputTextComplete(text: CharSequence) {
                    Toaster.show("你输入的验证码为:${text}")
                    clickResult?.onPswResult(text.toString())
                    dismiss()
                }
            })
            mHandler= Handler(Looper.getMainLooper())
            Looper.myQueue().addIdleHandler {
                mHandler?.postDelayed({
                    KeyboardUtils.showSoftInput(binding.verEdit)
                }, 500)

                false
            }
            setOnClickListener(binding.ivClose, binding.tvForgetPsw)
            return this
        }

        override fun onClick(view: View) {
            super.onClick(view)

            when (view) {
                binding.ivClose -> {
                    dismiss()
                }
                binding.tvForgetPsw -> {
                    SetPayPswActivity.start( getContext())
                    dismiss()
                }
            }
        }

        override fun createDialog(context: Context, themeId: Int): BaseDialog {
            val dialog = BottomSheetDialog(context, themeId)
            dialog.getBottomSheetBehavior().setSkipCollapsed(true)
            return dialog
        }

        var clickResult: ClickResult? = null

        interface ClickResult {
            fun onPswResult(string: String)
        }
    }
}